import 'package:flutter/material.dart';
import '../demo/ui_demo.dart';
import '../local/pages/context_header.dart';
class MyDemo extends StatelessWidget implements Demo {
  MyDemo(this.title);
  @override
  Widget build(BuildContext context) {
    return new HomePage(title: this.title,);
  }

  @override
  String title;

}

class HomePage extends StatefulWidget {
   String title;
  HomePage({key, this.title});
  @override
  State<StatefulWidget> createState() => new _HomePageState(title: this.title);
}

class _HomePageState extends State<HomePage> with WidgetsBindingObserver  {
  int count = 0;
  String title;
  _HomePageState({key, this.title});
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }
  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }
  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }
  @override
  Widget build(BuildContext context) {
    String ss="ssss";
    return Scaffold(
      appBar: AppBar(
      title: Text(this.title),
        actions: <Widget>[
          IconSource("floating button","01"),
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text("您已经点击按钮的次数", style: Theme.of(context).textTheme.title),
            Text(
              "$count",
              style: Theme.of(context).textTheme.display1,
            )
          ],
        ),
      ),
      floatingActionButton: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: <Widget>[
          Align(
            widthFactor: 2,
            alignment: FractionalOffset.bottomRight,
            child: FloatingActionButton(
              heroTag: 'btn1',
              onPressed: _incrementCounter,
              child: Icon(Icons.add),
            ),
          ),
          Align(
            widthFactor: 2,
            alignment: FractionalOffset.bottomRight,
            child: FloatingActionButton(
              heroTag: "btn2",
              onPressed: _decrementCounter,
              child: Icon(Icons.remove),
            ),
          )
        ],
      ),
    );
  }

  void _incrementCounter() {
    setState(() {
      count++;
    });
  }

  void _decrementCounter() {
    setState(() {
      count--;
    });
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    //页面生命周期状态日志
    LogUtils.instance.logState(state, this.runtimeType);
  }
}

